package com.dyc.caradvertisting.ui.fmt.find;


import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.dyc.caradvertisting.R;
import com.dyc.caradvertisting.bean.req.Register;
import com.dyc.caradvertisting.comm.GsonUtils;
import com.njh.tools.base.BaseFragment;
import com.njh.tools.common.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 忘记密码 发送短信
 */
public class FindPwdMsgFmt extends BaseFragment<FindPwdPresenter,FindPwdModel> implements FindPwdContract.View{

    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.tv_send_code)
    Button tvSendCode;
    @BindView(R.id.lin_btn)
    LinearLayout linBtn;
    @BindView(R.id.edt_vcode)
    EditText edtVcode;
    @BindView(R.id.edt_pwd)
    EditText edtPwd;
    @BindView(R.id.btn_send_message)
    Button btnSendMessage;

    public FindPwdMsgFmt() {
        // Required empty public constructor
    }

    public static FindPwdMsgFmt newInstance() {
        FindPwdMsgFmt fragment = new FindPwdMsgFmt();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        ButterKnife.bind(this, getView(inflater, container));
        return getView(inflater, container);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_find_pwd;
    }

    @Override
    public void initView(View baseView) {
        initToolbarNav(R.string.txt_message_chang);
    }

    @Override
    public boolean isSwipeBack() {
        return false;
    }

    @Override
    public void initPresenter() {

        mPresenter.setVM(this,mModel,this._mActivity);
    }

    @OnClick({R.id.tv_send_code, R.id.btn_send_message})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_send_code:
                break;
            case R.id.btn_send_message:
                String phone=etPhone.getText().toString();
                String Vcode = edtVcode.getText().toString();
                String pwd = edtPwd.getText().toString();
                if (TextUtils.isEmpty(phone)){
                    ToastUtils.showLong(this.getContext(),"请输入手机号");
                    return;
                }
                if (phone.length()!=11){
                    ToastUtils.showLong(this.getContext(),"手机号输入有误");
                    return;
                }
                if (TextUtils.isEmpty(Vcode)){
                    ToastUtils.showLong(this.getContext(),"请获取短信验证码");
                    return;
                }
                if (TextUtils.isEmpty(pwd)){
                    ToastUtils.showLong(this.getContext(),"请输入密码");
                    return;
                }
                if (6>pwd.length()){
                    ToastUtils.showLong(this.getContext(),"密码长度不能小于6位");
                    return;
                }
                if (16<pwd.length()){
                    ToastUtils.showLong(this.getContext(),"密码长度不能大于16位");
                    return;
                }
                Register register = new Register();
                register.setPhone(phone);
                register.setPsw(pwd);
                register.setVcode(Vcode);
                mPresenter.reqChangePassword(GsonUtils.getmGson().toJson(register));
                break;
        }
    }

    @Override
    public void finish() {
        this.onBackPressedSupport();
    }
}
